﻿@model IEnumerable<Von.Web.Structs.CommentInfo>
@{
    ViewData["Title"] = "评论管理";
    var CurrentComment = Model.FirstOrDefault(c => c.ID == ViewBag.CurrentIdx);
}
<h2>评论回复</h2>
<table id="CommentList" class="table">
    <thead>
        <tr>
            <th>点评值</th>
            <th>点评日期</th>
            <th>点评用户</th>
            <th>回复邮箱</th>
            <th>关注</th>
            <th>支持</th>
            <th>差评</th>
            <th></th>
        </tr>
    </thead>
    <tbody>
        @foreach (var item in Model)
        {
            <tr title="@item.Concern">
                <td>@Html.DisplayFor(modelItem => item.Evaluation)</td>
                <td>@Html.DisplayFor(modelItem => item.Publishedate)</td>
                <td>@Html.DisplayFor(modelItem => item.Publisher)</td>
                <td>@Html.DisplayFor(modelItem => item.Email)</td>
                <td>@Html.DisplayFor(modelItem => item.Concern)</td>
                <td>@Html.DisplayFor(modelItem => item.Support)</td>
                <td>@Html.DisplayFor(modelItem => item.Oppose)</td>
                <td>
                    <input type="button" class="btn-link" onclick="ShowComment(this, '@item.ID')" value="回复">
                    <input type="button" class="btn-danger" onclick="DeleteComment(this, '@item.ID')" value="删除">
                </td>
            </tr>
        }
    </tbody>
</table>
<div class="modal fade" id="CommentEditor" tabindex="-1" role="dialog" aria-labelledby="ModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header" style="background-color:aquamarine;">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="ModalLabel">评论回复</h4>
            </div>
            <div class="modal-body">
                <div class="form-group">
                    <label for="Content" class="control-label">评论内容</label>
                    <span id="Content"></span>
                </div>
                <div class="form-group">
                    <label for="ReplyContent" class="control-label">回复内容</label>
                    <textarea id="ReplyContent" class="form-control"></textarea>
                </div>
            </div>
            <div class="modal-footer">
                <input type="hidden" id="ID" />
                <div class="form-group">
                    <input value="回复" class="btn btn-default" onclick="SaveComment()" />
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    function ShowComment(btn, id) {
        var data = { ID: id };
        AjaxPostData("@Url.Ajax("GetComment")", data, function (result) {
            $("#ID").val(result.ID);
            $("#Content").text(result.Content);
            $("#ReplyContent").val(result.ReplyContent);
            $("#CommentEditor").modal("show");
        });
    }
    function SaveComment() {
        var data = { ID: $("#ID").val(), ReplyContent: $("#ReplyContent").val() };
        AjaxPostData("@Url.Ajax("ReplyComment")", data, function (data) { $("#CommentEditor").modal("hide"); });
    }
    function DeleteComment(btn, id) {
        var data = { ID: id };
        AjaxPostData("@Url.Ajax("DeleteComment")", data, function (data) { $(btn).parents("tr").remove(); });
    }
</script>
@Html.Import(Von.Web.Html.EImportSection.BodyTrailler, "HtmlCatalogInit",
    @<script>
        @(CurrentComment == null ? "" : "ShowComment(null, " + CurrentComment.ID + ");")
    </script>
)